//
//  HLEConfig.h
//  DownloadM3U8Tool_Example
//
//  Created by hle1879 on 2020/8/29.
//  Copyright © 2020 134344. All rights reserved.
//

#import <Foundation/Foundation.h>

#ifndef dispatch_queue_async_safe
#define dispatch_queue_async_safe(queue, block)\
    if (dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL) == dispatch_queue_get_label(queue)) {\
        block();\
    } else {\
        dispatch_async(queue, block);\
    }
#endif

#ifndef dispatch_main_async_safe
#define dispatch_main_async_safe(block) dispatch_queue_async_safe(dispatch_get_main_queue(), block)
#endif


/**
 * 发送通知
 */
#define MAIN_POST_NOTIFICATION(NAME,TASK) \
dispatch_main_async_safe(^{\
[[NSNotificationCenter defaultCenter] postNotificationName:NAME object:nil userInfo:(TASK == nil)?nil:@{@"TASK":TASK}];\
})


#define MAX_CONNECT_PERHOST  8 //默认最大的并发数
#define MAX_REQUEST_TIMEOUT 10 //请求的超时时间

#define HLEDownloadCompleteNotice @"HLEDownloadCompleteNotice" //下载完成
#define HLEDownloadFaileNotice @"HLEDownloadFaileNotice" //下载失败
#define HLEDownloadPauseNotice @"HLEDownloadPauseNotice"  //下载暂停
#define HLEDownloadCancelNotice @"HLEDownloadCancelNotice"  //下载取消
#define HLECombineMP4CompleteNotice @"HLECombineMP4CompleteNotice" //合成成功
#define HLECombineMP4FaileNotice @"HLECombineMP4FaileNotice" //合成失败

///定义错误的枚举
typedef NS_ENUM(NSUInteger, HLEError) {
    HLENoInitialized  = -1000,//SDK未初始化
    HLEParametersInvalid,//参数非法
    HLETASKNOCREATE,//任务还未创建
    HLEHandleCacheFailed,//缓存路径处理错误
    HLEHandleGetTsFileSizeError,//获取ts文件大小错误
    HLELogicError,//逻辑错误
    HLEM3uFileContentInvalid,//ts文件内容错误
    HLEM3uFileDownloadError,//m3u8文件下载错误
    HLEM3uFileUrlError,//m3u8文件地址错误
    HLETsFileDownloadError,//ts文件下载错误
    HLETsFileUrlInvalid,//ts文件失效
    HLECombineTsToMP4Error,//合并ts文件错误
    HLECombineTsToMP4NoFinish,//合并时ts文件未完全下载
    HLEUnKnow//未知错误
};

NS_ASSUME_NONNULL_BEGIN

@interface HLEConfig : NSObject

@property(nonatomic,assign)NSInteger downloadRetries;//下载失败的重试次数

@property(nonatomic,assign)BOOL supportBackground;//是否支持后台下载

@property(nonatomic,assign)BOOL supportBrokenPointDownload;//是否支持断点下载

@property(nonatomic,assign)NSInteger maximumConnectionsPerHost;//支持下载的最大并发数量

+(instancetype)defaultConfig;

-(instancetype)initWithDownloadRetries:(NSInteger)downloadRetries supportBackground:(BOOL)supportBackground supportBrokenPointDownload:(BOOL)supportBrokenPointDownload;

-(instancetype)initWithDownloadRetries:(NSInteger)downloadRetries supportBackground:(BOOL)supportBackground supportBrokenPointDownload:(BOOL)supportBrokenPointDownload maximumConnectionsPerHost:(NSInteger)maximumConnectionsPerHost;

@end

NS_ASSUME_NONNULL_END
